package com.tebiecloud.base.server.controller.feign;

import com.tebiecloud.base.client.model.IpLimitApi;
import com.tebiecloud.base.client.model.RateLimitApi;
import com.tebiecloud.base.client.model.entity.GatewayRoute;
import com.tebiecloud.base.client.service.IGatewayServiceClient;
import com.tebiecloud.base.server.service.GatewayIpLimitService;
import com.tebiecloud.base.server.service.GatewayRateLimitApiService;
import com.tebiecloud.base.server.service.GatewayRouteService;
import com.tebiecloud.common.model.ResultBody;
import com.tebiecloud.common.utils.ResultBodyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 网关接口
 * @Author: tebie
 * @Date: 2019-08-08 16:55
 */
@RestController
@RequestMapping("/feign/gateway")
public class GatewayController implements IGatewayServiceClient {

    @Autowired
    private GatewayIpLimitService gatewayIpLimitService;

    @Autowired
    private GatewayRateLimitApiService gatewayRateLimitApiService;

    @Autowired
    private GatewayRouteService gatewayRouteService;

    /**
     * 获取接口黑名单列表
     * @return
     */
    @GetMapping("listblack")
    @Override
    public ResultBody<List<IpLimitApi>> getBlackList() {
        return ResultBodyUtils.ok(gatewayIpLimitService.getBlackList());
    }

    /**
     * 获取接口白名单列表
     * @return
     */
    @GetMapping("listwhite")
    @Override
    public ResultBody<List<IpLimitApi>> getWhiteList() {
        return ResultBodyUtils.ok(gatewayIpLimitService.getWhiteList());
    }

    /**
     * 获取限流列表
     * @return
     */
    @GetMapping("listratelimit")
    @Override
    public ResultBody<List<RateLimitApi>> getRateLimitList() {
        return ResultBodyUtils.ok(gatewayRateLimitApiService.findRateLimitApiList());
    }

    /**
     * 获取路由列表
     * @return
     */
    @GetMapping("listroute")
    @Override
    public ResultBody<List<GatewayRoute>> getRouteList() {
        return ResultBodyUtils.ok(gatewayRouteService.findRouteList());
    }

}
